﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml;

namespace CharacterMap
{
    public class MessageService
    {
        public MessageService()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Theme"))
            {
                currentTheme = (ElementTheme)ApplicationData.Current.LocalSettings.Values["Theme"];
            }
            else
            {
                currentTheme = ElementTheme.Dark;
            }

            if (ApplicationData.Current.LocalSettings.Values.ContainsKey("AllowDataCollection"))
            {
                allowDataCollection = (bool)ApplicationData.Current.LocalSettings.Values["AllowDataCollection"];
            }
            else
            {
                allowDataCollection = true;
            }
        }

        public event EventHandler CurrentThemeChanged;

        ElementTheme currentTheme;
        public ElementTheme CurrentTheme
        {
            get { return currentTheme; }
            set
            {
                if (currentTheme != value)
                {
                    currentTheme = value;
                    if (CurrentThemeChanged != null) CurrentThemeChanged(this, EventArgs.Empty);
                    ApplicationData.Current.LocalSettings.Values["Theme"] = (int)CurrentTheme;
                }
            }
        }

        public event EventHandler AllowDataCollectionChanged;

        bool allowDataCollection;
        public bool AllowDataCollection
        {
            get { return allowDataCollection; }
            set
            {
                if (allowDataCollection != value)
                {
                    allowDataCollection = value;
                    if (AllowDataCollectionChanged != null) AllowDataCollectionChanged(this, EventArgs.Empty);
                    ApplicationData.Current.LocalSettings.Values["AllowDataCollection"] = allowDataCollection;
                }
            }
        }

        static readonly MessageService current = new MessageService();
        public static MessageService Current
        {
            get { return current; }
        }
    }
}
